<?php
class retrieve_system_prefs extends retrieve_base{

	private $module_display_options 	= array();

/**
	* function produces abstract structure of modules db structure
	*
    * used to generate the table structure required abstract function that passes an abstract
	* representation of the desired table structure to the proper database module which will
	* interpet the abstract and convert it into a valid SQL Create table structure.
	*
	* @return Array list of abstract table definitions for this module
	*/
	function create_table(){
		$tables = array();
		/**
		* Table structure for table 'user_info'
		*/
		
		$fields = array(
		array("system_preference_name"		,"varchar(255)"		,"NOT NULL"	,"default ''"),
		array("system_preference_label"		,"varchar(255)"		,"NOT NULL"	,"default ''"),
		array("system_preference_client"	,"unsigned integer"	,"NOT NULL"	,"default '0'"),
		array("system_preference_value"		,"varchar(255)"		,"NOT NULL"	,"default ''"),
		array("system_preference_options"	,"varchar(255)"		,"NOT NULL"	,"default ''"),
		array("system_preference_module"	,"varchar(255)"		,"NOT NULL"	,"default 'SYSPREFS_'")
		);
		$primary ="";
		$tables[count($tables)] = array("system_preferences", $fields, $primary);
		/**
		* Table structure for table 'user_info'
		*/
		
		$fields = array(
			array("smd_identifier"						,"unsigned integer"	,"NOT NULL"	,"auto_increment"),
			array("smd_client"							,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("smd_audience"						,"TEXT"				,"NOT NULL"	,"default ''"),
			array("smd_subject"							,"TEXT"				,"NOT NULL"	,"default ''"),
			array("smd_doctypes"						,"TEXT"				,"NOT NULL"	,"default ''"),
			array("smd_copy_location"					,"VARCHAR(255)"		,"NOT NULL"	,"default ''"),
			array("smd_publisher_contact_information"	,"VARCHAR(255)"		,"NOT NULL"	,"default ''")
		);

		$primary ="smd_identifier";
		$tables[count($tables)] = array("system_metadata_defaults", $fields, $primary);

		return $tables;
	}

	/**
	* call the initialisation function only when this module is created
	*/
	function create_client_details($parameters){
		$client_identifier = $this->check_parameters($parameters,"client_identifier",-1);
		/**
		* insert available_fields data
		*/
		$max = count($this->preferences);
		for ($i=0;$i<$max;$i++){
			$ok=0;
			if (($this->parent->server[LICENCE_TYPE]==ECMS)){
				$ok =1;
			} else if (($this->parent->server[LICENCE_TYPE]==MECM)){
				if ($this->preferences[$i][5]=="ALL" || $this->preferences[$i][5]=="MECM"){
					$ok =1;
				}
			} else{
				if ($this->preferences[$i][5]=="ALL"){
					$ok =1;
				}
			} 
			if ($ok==1){
				$sql ="insert into system_preferences (system_preference_name, system_preference_label, system_preference_client, system_preference_value, system_preference_options, system_preference_module) 
					values 
					('".$this->preferences[$i][0]."', 'LOCALE_".strtoupper($this->preferences[$i][0])."', $client_identifier, '".$this->preferences[$i][2]."', '".$this->preferences[$i][3]."', '".$this->preferences[$i][4]."');";
				$this->db->query($sql);
			}
		}
//		$this->db->query("INSERT INTO system_metadata_defaults VALUES(\"1\", \"1\", \"Children\r\nExpert\r\nUK Citizens\r\nScotish Citizens\r\nN.Ireland Citizens\r\nWelish Citizens\", \"Heart disease/Stroke\r\nCrime/crime reduction; Young People\r\nCrime/crime reduction; Adults\r\nCrime/crime reduction; OAPs\", \"Act of Parliament\r\nAdvertisement\r\nAgenda\r\nArticle\r\nAnnual report\r\nAtlas\r\nBriefing note\r\nBudget\r\nCall for expressions of interest\r\nCall for tenders\r\nCall for papers\", \"www.libertas-solutions.com/copyright/index.php\", \"libertas-Solutions, 130 Markethill Rd, Armagh, N.Ireland, email info@libertas-solutions.com\");");
		
	}
		

}
?>